$(function() {
    var bdbDomainList = {
        /* 初始数据 */
        defData: {
            pageSize: 20 // 每页分页数量.
        },

        /* 页面状态 */
        pageState: {
            search: '', // 搜索框值.
            page: 1, // 分页值.
            productTypeId: '', // 产品分类id.
            sort: { /* 排序 */
                create_time: 'def' // 创建时间(def：默认; asc:正序; desc：倒序).
            },
            noData: 'def' // search: 没有匹配的结果; def: 暂无记录.
        },
        resetPageState: function() {
            this.pageState = {
                search: '',
                page: 1,
                productTypeId: '',
                sort: {
                    create_time: 'def'
                },
                noData: 'def'
            };

            this.list();
        },

        /* 添加 */
        addEvent: function() {
            var _this = this,
                addFormVerify;

            // 第一步表单验证.
            addFormVerify = $('#bdb-domain-add-first-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.addFirstSetpSubmit(form);
                }
            });

            // 点击添加响应事件.
            $('#bdb-domain-add').off('click').on('click', function() {
                _this.addFirstSetpDefDataProc(addFormVerify); // 默认数据处理.
            });

            // 上一步.
            var addDomainFirstEle = $("#bdb-domain-add-first-dialog"),
                addDomainSecondEle = $('#bdb-domain-add-second-dialog');
            $('.bdb-domain-pre-step-btn').off('click').on('click', function() {
                addDomainFirstEle.show();
                addDomainSecondEle.hide();
            });
        },
        addFirstSetpDefDataProc: function(verifyObj) {
            var _this = this,
                verifyObj = verifyObj;

            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/CustomerDomainManager/domainAddInit', function(response) {
                if (response.code == 0) {
                    var firstDialogEle = $('#bdb-domain-add-first-dialog');
                    if (response.data.productType) {
                        var pTHtml = bdbMain.attr.selDefOption;
                        $.each(response.data.productType, function(i, n) {
                            pTHtml += '<option value="' + i + '">' + n + '</option>';
                        });
                        firstDialogEle.find('#productTypeId').html(pTHtml);
                    }

                    if (response.data.sourceList) {
                        var sTHtml = bdbMain.attr.selDefOption;
                        $.each(response.data.sourceList, function(i, n) {
                            sTHtml += '<option value="' + n.template_id + '">' + n.template_name + '</option>';
                        });
                        firstDialogEle.find('#templateId').html(sTHtml);
                    }

                    bdbMain.mLSleep({loading: false}, function() {
                        $(".bdbBlankEle").bdbDialog({
                            ele: '#bdb-domain-add-first-dialog',
                            formObj: verifyObj,
                            form: $('#bdb-domain-add-first-form'),
                            reset: true
                        });
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }   
            }, 'json');
        },
        addFirstSetpSubmit: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/CustomerDomainManager/domainAddCheck', {
                productTypeId: form.find("#productTypeId").val(),
                icp: form.find("#icp").val(),
                templateId: form.find("#templateId").val(),
                domains: form.find("#domains").val()
            }, function(response) {
                if (response.code == 0) {
                    _this.addSecondeSetpVerify(response.data);
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        addSecondeSetpVerifyTpl: function(data) {
            var tpl = '',
                j = 0;

            $.each(data, function(i, n) {
                if (j == 0) {
                    var secondSetpEle = $('#bdb-domain-add-second-form');
                    secondSetpEle.find('#bdb-domain-product-text span').text(n.productTypeName);
                    secondSetpEle.find('#bdb-domain-isp-text span').text(n.icp);
                }

                tpl += '<div class="row">\
                             <div class="form-ele-domain">\
                                <input type="hidden" name="domain[]" value="' + n.domain + '">\
                                <div class="bdb-ellipsis bdb-m-w-200" title="' + n.domain + '">' + n.domain + '</div>\
                             </div>\
                             <div class="form-ele-testurl">\
                                 <input type="text" class="bdb-form-control bdb-urls" name="testUrl[' + (j++) +']" autocomplete="off" \
                                    value="http://' + n.domain + '/" placeholder="' + bdbMain.attr.placeholder.url + '" \
                                    data-rule-urlProc="true" data-msg-urlProc="请输入正确的测试url" \
                                    data-rule-required="true" data-msg-required="请输入测试url">\
                             </div>\
                             <div class="form-ele-domainnote">\
                                 <input type="text" class="bdb-form-control bdb-notes" name="domainNote[]"  autocomplete="off">\
                             </div>\
                           </div>';
            });

            return tpl;
        },
        addSecondeSetpVerify: function(data) {
            var _this = this,
                addFormVerify,
                listHtml = '';

            listHtml = _this.addSecondeSetpVerifyTpl(data);
            $("#bdb-domain-add-second-dialog .list").html(listHtml);
            addFormVerify = $('#bdb-domain-add-second-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },  
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.addSecondSetpSubmit(form);
                }
            });

            bdbMain.mLSleep({maskDown: 99, loading: false}, function() {
                $("#bdb-domain-add-first-dialog").hide();

                $('.bdbBlankEle').bdbDialog({
                    ele: '#bdb-domain-add-second-dialog',
                    formObj: addFormVerify,
                    form: $("#bdb-domain-add-second-form"),
                    reset: true,
                    animation: 'def'
                });
            });
        },
        addSecondSetpSubmit: function(form) {
            var _this = this,
                form = $(form),
                params = {domainList: []};

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            var list = form.find(".list .row"),
                obj = {},
                inputs,
                addFirstStepFrom = $("#bdb-domain-add-first-form"),
                icp = addFirstStepFrom.find("#icp").val(),
                templateId = addFirstStepFrom.find("#templateId").val(),
                productTypeId = addFirstStepFrom.find("#productTypeId").val();

            $.each(list, function(i, n) {
                inputs = $(n).find("input");
                obj = {
                    productTypeId: productTypeId,
                    icp: icp,
                    templateId: templateId,
                    domain: inputs.eq(0).val(),
                    testUrl: inputs.eq(1).val(),
                    domainNote: inputs.eq(2).val()
                };
                params.domainList.push(obj);
            });

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/CustomerDomainManager/domainAdd', params, function(response) {
                if (response.code == 0) {
                    $(".js-bdb-dialog-cancel").click();
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '添加成功.'}});
                    bdbMain.mLSleep({}, function() {
                        _this.resetPageState();
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 搜索 */
        searchEvent: function() {
            var _this = this,
                searchInputEle = $('.bdb-search-input');

            searchInputEle.off('focusin').on('focusin', '.search-text', function(e) {
                var _cThis = $(this),
                    _btnEle = $(this).parent().find('span');

                if (!_btnEle.hasClass('search-clear')) {
                    _cThis.animate({width: '240px'}, 500);
                    _btnEle.animate({left: '240px'}, 500, function() {
                        _btnEle.removeClass('search-gray').addClass('search-blue');
                    });
                }
            });

            searchInputEle.off('click').on('click', 'span', function(e) {
                var left = parseInt($(this).css('left'));
                if ($(this).hasClass('search-blue') && left > 0) {
                    _this.pageState.search = searchInputEle.find('.search-text').val();
                    _this.pageState.noData = 'search';
                    $(this).removeClass('search-blue').addClass('search-clear');
                    _this.list();
                } else if (left > 0) {
                    _this.pageState.search = '';
                    _this.pageState.noData = 'def';
                    searchInputEle.find('.search-text').val('');
                    $(this).removeClass('search-clear').addClass('search-blue');
                    _this.list();
                }
            });
        },

        searchProc: function() {
        
        },

        /* 服务器组设置 */
        serverGroupSetEvent: function() {
            var _this = this;
            $('#bdb-domain-servers-setting').off('click').on('click', function() {
                // 请选择要修改服务器组的记录行.
                if ($('.bdb-list .check-icon.checkYes').length <= 0) {
                    bdbMain.mLRManag({alert: {type: 2, msg: '请选择要修改服务器组的记录行!'}});
                    return ;
                }

                _this.serverGroupSetProc($(this));
            });
        },
        serverGroupSetProc: function() {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/CustomerDomainManager/getServerGroupList', function(response) {
                if (response.code == 0) {
                    var serverSetDialogEle = $('#bdb-server-set-dialog');
                    if (response.data.cache) {
                        var cacheHtml = '';
                        $.each(response.data.cache, function(i, n) {
                            cacheHtml += '<div class="row">\
                                             <input class="bdb-domain-caches bdb-f-l" type="checkbox" name="caches[]" value="' + n.server_group_id + '" \
                                                data-rule-required="true" data-msg-required="请选择缓存层">\
                                             <span class="bdb-f-l">' + n.server_name + '</span>\
                                          </div>';
                        });
                        serverSetDialogEle.find('#bdb-domain-cache-layer').html(cacheHtml);
                    }

                    if (response.data.storage) {
                        var storageHtml = bdbMain.attr.selDefOption;
                        $.each(response.data.storage, function(i, n) {
                            storageHtml += '<option value="' + n.server_group_id + '">' + n.server_name + '</option>';
                        });
                        serverSetDialogEle.find('#bdb-domain-master-storage, #bdb-domain-backup-storage').html(storageHtml);
                    }

                    bdbMain.mLSleep({loading: false}, function() {
                        _this.serverGroupSetVerify();
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        serverGroupSetVerify: function() {
            var _this = this,
                formVerify;

            // 验证.
            formVerify = $('#bdb-server-set-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function(error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        element.parents(".bdb-vc").find('.help-block').remove();
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.serverGroupSetSave(form);
                }
            });

            // dialog.
            $('.bdbBlankEle').bdbDialog({
                ele: '#bdb-server-set-dialog',
                formObj: formVerify,
                form: $('#bdb-server-set-form'),
                reset: true
            });
        },
        serverGroupSetSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 获取数据.
            var ids = '',
                cacheList = '';

            if ($(".bdb-list-row .checkYes").length > 0) {
                var arr = [];
                $(".bdb-list-row .checkYes").each(function(i, n) {
                    arr.push($(n).parent().attr('data-id'));
                });
                ids = arr.join(',');
            }

            if ($(".bdb-domain-caches:checked").length > 0) {
                var arr = [];
                $(".bdb-domain-caches:checked").each(function(i, n) {
                    arr.push($(n).val());
                });
                cacheList = arr.join(',');
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/CustomerDomainManager/setDomainServerGroup', {
                id: ids,
                cacheList: cacheList,
                masterStorage: form.find('#bdb-domain-master-storage').val(),
                backupStorage: form.find('#bdb-domain-backup-storage').val()
            }, function(response) {
                if (response.code == 0) {
                    $(".js-bdb-dialog-cancel").click();
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '设置成功'}});
                    bdbMain.mLSleep({}, function() {
                        _this.list({page: _this.pageState.page});
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 修改源站模版 */
        modifySourceTplEvent: function() {
            var _this = this;
            $('#bdb-domain-change-dispose').off('click').on('click', function() {
                // 请选择要修改源站模版的记录行.
                if ($('.bdb-list .check-icon.checkYes').length <= 0) {
                    bdbMain.mLRManag({alert: {type: 2, msg: '请选择要修改源站模版的记录行!'}});
                    return ;
                }

                _this.modifySourceTplProc($(this));
            });
        },
        modifySourceTplProc: function(ele) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/CustomerDomainManager/domainAddInit', function(response) {
                if (response.code == 0) {
                    if (response.data.sourceList) {
                        var sourceTplHtml = bdbMain.attr.selDefOption;
                        $.each(response.data.sourceList, function(i, n) {
                            sourceTplHtml += '<option value="' + n.template_id + '">' + n.template_name + '</option>';
                        });
                        $('#bdb-source-tpl-dialog #templateId').html(sourceTplHtml);
                    }

                    bdbMain.mLSleep({loading: false}, function() {
                        _this.modifySourceVerify();
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        modifySourceVerify: function() {
            var _this = this,
                formVerify;

            // 验证.
            formVerify = $('#bdb-source-tpl-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.modifySourceSave(form);
                }
            });

            // dialog.
            $('.bdbBlankEle').bdbDialog({
                ele: '#bdb-source-tpl-dialog',
                formObj: formVerify,
                form: $('#bdb-source-tpl-form'),
                reset: true
            });
        },
        modifySourceSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 获取数据.
            var ids = '';
            if ($(".bdb-list-row .checkYes").length > 0) {
                var arr = [];
                $(".bdb-list-row .checkYes").each(function(i, n) {
                    arr.push($(n).parent().attr('data-id'));
                });
                ids = arr.join(',');
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/CustomerDomainManager/setTemplate', {
                domainId: ids,
                templateId: form.find("#templateId").val()
            }, function(response) {
                if (response.code == 0) {
                    $(".js-bdb-dialog-cancel").click();
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '修改成功'}});
                    bdbMain.mLSleep({}, function() {
                        _this.list({page: _this.pageState.page});
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 产品选择 */
        productSelEvent: function() {
            var _this = this,
                ele = $('#bdb-domain-header-product-list');

            ele.off('click').on('click', 'li', function(e) {
                e.stopPropagation();
                _this.pageState.productTypeId = $(this).attr('data-id');
                $(this).parent().hide();
                _this.list();
            });

            $('#bdb-domain-header-product')
                .off('click').on('click', function(e) {
                    $(this).find('span').css('background-color', '#fafafa');
                    if (ele.find('li').length <= 0) {
                        _this.productSelProc($(this));
                    } else {
                       ele.fadeIn();
                    }
                })
                .off('mouselevae').on('mouseleave', function(e) {
                    ele.hide();
                    $(this).find('span').css('background-color', '#fff');
                });
        },
        productSelProc: function(ele) {
            var _this = this,
                ele = ele.find('#bdb-domain-header-product-list');

            // 数据填充.
            $.post('/CustomerDomainManager/domainAddInit', function(response) {
                if (response.code == 0) {
                    if (response.data.productType) {
                        var pTHtml = bdbMain.attr.listDefOption;
                        $.each(response.data.productType, function(i, n) {
                            pTHtml += '<li data-id="' + i + '">' + n + '</li>';
                        });
                        $('#bdb-domain-header-product-list').html(pTHtml);
                    }

                    // 显示.
                    ele.fadeIn();
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },

        /* 按创建时间排序 */
        sortEvent: function() {
            var _this = this;
            $('.bdb-table-header').off('click.sortEvent').on('click.sortEvent', function(e) {
                e.stopPropagation();
                var id = $(e.target).attr('id'),
                    arrow = 'top';

                // 排序.
                switch (id) {
                    case 'bdb-domain-createtime': // 创建时间.
                        if (_this.pageState.sort.create_time == 'asc') {
                            _this.pageState.sort.create_time = 'desc';
                            arrow = 'bottom';
                        } else {
                            _this.pageState.sort.create_time = 'asc';
                        }
                        break;
                    default:
                        return ;
                }

                // 箭头.
           
                _this.list();
            });
        },

        /* 配置完成 */
        configDoneEvent: function() {
            var _this = this;
            $('#bdb-domain-config-done').off('click').on('click', function() {
                // 请选择要配置完成的记录行!.
                if ($('.bdb-list .check-icon.checkYes').length <= 0) {
                    bdbMain.mLRManag({alert: {type: 2, msg: '请选择要配置完成的记录行!'}});
                    return ;
                }

                _this.configDoneProc();
            });
        },
        configDoneProc: function() {
            var _this = this,
                ids = '';

            if ($(".bdb-list-row .checkYes").length > 0) {
                var arr = [];
                $(".bdb-list-row .checkYes").each(function(i, n) {
                    arr.push($(n).parent().attr('data-id'));
                });
                ids = arr.join(',');
            }

            bdbMain.confirm({
                textInfo: {
                    content: '确定配置完成？',
                    btn: {}
                },
                // note: true,
                params: {
                    url: '/CustomerDomainManager/configureComplete',
                    data: {
                        id: ids
                    }
                },
                callback: function(ele, params) {
                    _this.configDoneCallbackProc(ele, params);
                }
            });
        },
        configDoneCallbackProc: function(ele, params) {
            var _this = this;
            ele.hide();

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, loading: true});
            $.post(params.url, {
                id: params.data.id
            }, function(response) {
                if (response.code == 0) {
                    bdbMain.mLRManag({mask: false, loading: false, alert: {type: 1, msg: '批量配置成功'}});
                    bdbMain.mLSleep({}, function() {
                        _this.list();
                    });
                } else {
                    bdbMain.mLSleep({loading: false, alertHC: {msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 列表 */
        listEvent: function() {
            var _this = this;
            $('.bdb-list').off('click.listEvent').on('click.listEvent', function(e) {
                var ele = $(e.target),
                    id = ele.parents('.bdb-list-row').attr('data-id');

                if (ele.parents('.js-bdb-prevent-bubble').length || ele.hasClass('js-bdb-prevent-bubble')) {
                    e.stopPropagation();
                }

                if (ele.hasClass('js-domain-detail')) { // 查看详情.
                    _this.detail(id);
                }
            });
        },
        detailProcTpl: function(data) {
            var tpl = '',
                cacheLayer = '',
                masterStorage = '暂无',
                bakStorage = '暂无';

            $.each(data.serverGroup.cacheList, function(i, n) {
                cacheLayer += '<div class="content-cache-layer-row bdb-ellipsis">' + n.server_name + '</div>';
            });

            if (data.serverGroup.masterStorage[0]) {
                masterStorage = data.serverGroup.masterStorage[0]['server_name'];
            }

            if (data.serverGroup.backupStorage[0]) {
                bakStorage = data.serverGroup.backupStorage[0]['server_name'];
            }

            $('#bdb-domain-detail .title span').text(data.domainInfo.domain_name);
            tpl += '<div id="config-done-left">\
                        <div class="content-row">\
                            <div class="content-left">产品：</div>\
                            <div class="content-right">' + data.domainInfo.product_type_word + '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">状态：</div>\
                            <div class="content-right">' + data.domainInfo.domain_status_word + '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">源站模版：</div>\
                            <div class="content-right bdb-ellipsis">' + data.domainInfo.template_name+ '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">网址备案号：</div>\
                            <div class="content-right bdb-ellipsis">' + data.domainInfo.icp + '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">更新时间：</div>\
                            <div class="content-right">' + data.domainInfo.update_time_word + '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">创建时间：</div>\
                            <div class="content-right">' + data.domainInfo.create_time_word + '</div>\
                        </div>\
                    </div>\
                    <div id="split-line"></div>\
                    <div id="config-done-right">\
                        <div class="content-row">\
                            <div id="content-cache-layer">缓存层：</div>\
                            <div id="content-cache-layer-list">\
                                <div class="bdb-h-4"></div>' + cacheLayer + '<div class="bdb-h-4"></div>\
                            </div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">存储层(主)：</div>\
                            <div class="content-right bdb-ellipsis">' + masterStorage + '</div>\
                        </div>\
                        <div class="content-row">\
                            <div class="content-left">存储层(备)：</div>\
                            <div class="content-right bdb-ellipsis">' + bakStorage + '</div>\
                        </div>\
                    </div>';

            return tpl;
        },
        detail: function(id) {
            var _this = this;

            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/CustomerDomainManager/domainInfo', {
                id: id
            }, function(response) {
                if (response.code == 0) {
                    var contentHtml = '';
                    contentHtml = _this.detailProcTpl(response.data);
                    $('#bdb-domain-detail .content').empty().html(contentHtml);
                    bdbMain.mLSleep({mask: false, loading: false}, function() {
                        $(".bdbBlankEle").bdbDialog({
                            ele: '#bdb-domain-detail',
                            reset: false
                        });
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            });
        },
        listProc: function(data) {
            var tpl = '';
            $.each(data.list, function(i, n) {
                tpl += '<div class="bdb-list-row" data-id="' + n.domain_id + '">\
                            <div class="bdb-mx-w-col1 check-icon checkNo"></div>\
                            <div class="bdb-mx-w-col2 bdb-ellipsis js-bdb-prevent-bubble js-domain-detail">' + n.domain_name + '</div>\
                            <div class="bdb-mx-w-col3 bdb-ellipsis">' + data.outerSuffix + '</div>\
                            <div class="bdb-mx-w-col4 bdb-ellipsis">' + n.template_name + '</div>\
                            <div class="bdb-mx-w-col5 bdb-ellipsis bdb-pad-l-12">' + n.product_type + '</div>\
                            <div class="bdb-mx-w-col6 bdb-ellipsis">' + n.domain_status_words + '</div>\
                            <div class="bdb-mx-w-col7">' + n.createTime + '</div>\
                            <div class="bdb-mx-w-col8 js-bdb-prevent-bubble">\
                                <a class="bdb-option-btn" href="/CustomerDomainRelation/relationElc/' + n.domain_id + '">解析关系</a>\
                            </div>\
                        </div>';
            });

            return tpl;
        },
        list: function(obj) {
            var _this = this,
                obj = obj || {page: 1};

            _this.pageState.page = obj.page;
            bdbMain.mLRManag({mask: true, loading: true});

            // 获取列表.
            $.post('/CustomerDomainManager/domainList', {
                pageSize: _this.defData.pageSize,
                pageNumber: _this.pageState.page,
                productTypeId: _this.pageState.productTypeId,
                query: _this.pageState.search,
                orderBy: _this.pageState.sort
            }, function(response) {
                var totalRowCnt = 0,
                    listHtml = '';

                if (response.code == 0) {
                    totalRowCnt = parseInt(response.data.totalCount) > 0 ? parseInt(response.data.totalCount) : 0;
                    listHtml = _this.listProc(response.data);
                    _this.listNull(totalRowCnt);
                    $('.bdb-list').html(listHtml);
                    bdbMain.mLSleep({mask: false, loading: false});

                    // 分页插件.
                    $("#js-bdb-creatPage").bdbPagination({
                        totalRowCnt: totalRowCnt,
                        currentPage: _this.pageState.page,
                        pageSize: _this.defData.pageSize
                    });
                    $('.bdb-record-cnt').html(bdbMain.pageInfo.recordCnt.replace('{cnt}', totalRowCnt));
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
			    $('.check-all-icon').removeClass('checkAll').addClass('checkNone'); // 撤销全选.
            });
        },
        listNull: function(totalRowCnt) {
            var noResult = $('.bdb-no-result'),
                noSearchRecord = $('.bdb-no-search-record');

            if (totalRowCnt <= 0) {
                if (this.pageState.noData == 'search') { // 查询.
                    noResult.hide();
                    noSearchRecord.show();
                } else { // 暂无记录.
                    noResult.show();
                    noSearchRecord.hide();
                }
            } else {
                noResult.hide();
                noSearchRecord.hide();
            }
        },

        /* 分页 */
        pageEvent: function() {
            var　_this = this;

            /* 页码事件 */
            $('.bdb-creatPage').off('click').on('click', '.bdb-pagination', function(e) {
                e.preventDefault();
                var ele = $(e.target),
                    page = parseInt(ele.text());

                if (!isNaN(page)) {
                    _this.list({page: page});
                }
            });
        },

	  	/* 屏幕高度适应 */
	  	contentSizeResize: function () {
			$(window).resize(function() {
			  	$('.bdb-list').bdbScreenH(1);
			});
		},

        /* 初始化 */
        init: function() {
            var _this = this;

            _this.addEvent(); // 添加.
            _this.list(); // 加载列表.
            _this.listEvent(); // 列表操作事件.
            _this.pageEvent(); // 分页事件.
            _this.searchEvent(); // 搜索.
            _this.modifySourceTplEvent(); // 修改源站模版.
            _this.sortEvent(); // 排序事件.
            _this.productSelEvent(); // 产品分类事件.
            _this.serverGroupSetEvent(); // 修改服务器组.
			_this.contentSizeResize(); //内容区域屏幕适应.
            _this.configDoneEvent(); // 配置完成.

            $('.bdb-container').bdbCheckBox(); // 全选插件调用.
            $('.bdb-list').bdbScreenH(1); // 右侧列表区域自适应.
        }
    };

    bdbDomainList.init();
});
